package com.lemon.components.wechart.order.user;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.commons.lang3.StringUtils;

import com.lemon.components.common.order.ValidateOrderBase;
import com.lemon.components.wechart.enums.SnsapiScopeEnum;

public class UserCodeOrder extends ValidateOrderBase {
	private static final long serialVersionUID = 2064982947381491980L;
	private String redirectUri;
	private String responseType = "code";
	private String appid;
	private String state;
	private SnsapiScopeEnum scope;

	public String getRedirectUri() {
		return redirectUri;
	}

	public void setRedirectUri(String redirectUri) {
		try {
			this.redirectUri = URLEncoder.encode(redirectUri, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	public String getResponseType() {
		return responseType;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public SnsapiScopeEnum getScope() {
		return scope;
	}

	public void setScope(SnsapiScopeEnum scope) {
		this.scope = scope;
	}

	@Override
	public void check() {
		validateNotNull(redirectUri,"redirectUri回调地址不能空");
		validateNotNull(appid,"appid不能为空");
		validateNotNull(scope,"scope不能为空");
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "UserCodeOrder [redirectUri=" + redirectUri + ", responseType=" + responseType + ", appid=" + appid + ", state=" + state + ", scope=" + scope + ", toString()=" + super.toString() + "]";
	}

	/**
	 * @return the state
	 */
	public String getState() {
		if(StringUtils.isBlank(state)){
			return StringUtils.EMPTY;
		} else {
			state = "&state="+state;
			return state;
		}
	}

	/**
	 * @param state the state to set
	 */
	public void setState(String state) {
		this.state = state;
	}
}
